//
//  ZJFedeBackViewController.swift
//  mini
//
//  Created by Mac on 2017/5/22.
//  Copyright © 2017年 Mac. All rights reserved.
//

import UIKit
import SnapKit

class ZJFedeBackViewController: UIViewController,UITextViewDelegate{
    
    var rigthItem:UIBarButtonItem?

    var textView :ZJTextView = {
        
        let textV:ZJTextView = ZJTextView()
        
        textV.myBorderWidth = 1
        
        textV.placeholder =  "  请输入反馈信息";
        
        textV.placeholderColor =  kScriptGrayColor;
        
        textV.placeholderFont = UIFont.systemFont(ofSize: 14)
        
        return textV
    }()
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false
        setUpUI()
       
    }
    
    func setUpUI()  {
        
        title = "反馈信息"
        
        view.backgroundColor = kGlobelBgColor
        
        
        //放到懒加载中不生效
        textView.delegate = self
        
        view.addSubview(textView)
        
        textView.snp.makeConstraints({ (make) in
            
            make.top.equalTo(view).offset(10+64);
            
            make.leading.equalTo(view).offset(0);
            
            make.trailing.equalTo(view).offset(0);
            
            make.height.equalTo(215);
            
        })
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:"YC_Nav_Back"), style: .plain, target: self, action: #selector(self.back))
        
        rigthItem = UIBarButtonItem(title: "提交", style: .plain, target: self, action: #selector(self.commit))
        
        navigationItem.rightBarButtonItem = rigthItem
        
        rigthItem?.isEnabled = false
        
        
        
    }
    func back()  {
        
        navigationController?.popViewController(animated: true)
        
    }
    

    func commit()  {
        
        let time: TimeInterval = 1.0
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time){
           YCHud.show(withStatus: "提交反馈成功")
            self.navigationController?.popViewController(animated: true)
           
        }
        
        
    }
    
   
    
    func textViewDidChange(_ textView: UITextView) {
        
        let str = textView.text as NSString
        
        if str.length>0 {
            rigthItem?.isEnabled = true;
        }else{
            rigthItem?.isEnabled = false;
        }
    }

    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
 


}

